
#ifndef OCTREE_H_
#define OCTREE_H_

#include "../collider/CollisionRay.h"

#include "../object/GameObject.hpp"

#include "../collider/CollisionDetector.h"

class Octree {
    protected:
        int level;
        glm::vec3 position;
        float halfSize;
        std::vector<Octree*> nodes;
        std::vector<GameObject*> objects;

    public:
        static unsigned MAX_OBJECTS;
        static int MAX_LEVEL;

        Octree(int level, glm::vec3, float);
        virtual ~Octree();

        int getDepth();

        void clear();

        void split();

        int getIndex(glm::vec3, float);
        void insert(GameObject*);
        void subdivide();

        void detectCollisions();
        void detectCollisions(GameObject*);

        void intersectsRay(CollisionRay*, Asteroid*&, float = FLT_MAX);

        virtual void print(std::string = "");
};

#endif /* OCTREE_H_ */
